home *** CD-ROM | disk | FTP | other *** search
- /********* Listing 3 ********************** TESTARRY.C ****
- * TESTARRY.C : Test the dynamic_array
- * (c) C Gazette, see Listing 1 for usage.
- *********************************************************/
- #include "array.h"
- #include <stdio.h>
-
- void main()
- {
- int i;
- dynamic_array da, *dap;
- create_array(&da, 20);
- for(i = 0; i < 20; i++)
- *value(&da, i) = i * 2; /* assign a value to each element */
- dap = make_heap_array(20);
- for(i = 0; i < 20; i++)
- *value(dap, i) = i * 3;
- for(i = 0; i < 20; i++)
- printf("stack[%d] = %d, heap[%d] = %d\n",
- i, *value(&da,i), i, *value(dap, i) );
- /* *value(dap, 20) = 100; */ /* a test of the error system */
- /* must always remember to clean up! */
- release_heap_array(dap);
- free_array(&da);
- }